<html xmlns="http://www.w3c.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	xmlns:f="http://java.sun.com/jsf/core">
<h:head>
	<h:outputScript library="js" name="index.js" target="head" />
	<h:outputStylesheet library="css" name="style.css" />
</h:head>
<h:body>
	<h1>eID Test PKI Console</h1>
	<p:messages id="messages" globalOnly="true" />
	<h:form id="caForm">
		<p:dataTable var="row" value="#{CertificateAuthorities}"
			paginator="true" rows="10" id="table">
			<f:facet name="header">Root Certificate Authorities</f:facet>
			<f:facet name="footer">
				<p:commandLink
					actionListener="#{certificateAuthorityController.prepareAdd}"
					id="addLink" oncomplete="addDialog.show();"
					styleClass="ui-icon ui-icon-circle-plus"
					update=":addDialogForm,:messages" />
				<p:tooltip for="addLink" value="Add certificate authority" />
			</f:facet>
			<p:column sortBy="#{row.name}">
				<f:facet name="header">Name</f:facet>
				<h:outputText value="#{row.name}" />
			</p:column>
			<p:column>
				<f:facet name="header">Subject</f:facet>
				<h:outputText value="#{row.subject}" />
			</p:column>
			<p:column>
				<f:facet name="header">Key Size</f:facet>
				<h:outputText value="#{row.keySize}" />
			</p:column>
			<p:column>
				<f:facet name="header">Not Before</f:facet>
				<h:outputText value="#{row.notBefore}">
					<f:convertDateTime pattern="dd/MM/yyyy HH:mm" timeZone="CET" />
				</h:outputText>
			</p:column>
			<p:column>
				<f:facet name="header">Not After</f:facet>
				<h:outputText value="#{row.notAfter}">
					<f:convertDateTime pattern="dd/MM/yyyy HH:mm" timeZone="CET" />
				</h:outputText>
			</p:column>
			<p:column>
				<f:facet name="header">
					<h:outputText value="Actions" />
				</f:facet>
				<h:panelGroup>
					<p:commandButton id="viewLink" icon="ui-icon-search"
						actionListener="#{certificateAuthorityController.viewCandidate}"
						oncomplete="viewDialog.show()" update=":viewDialogForm,:messages">
						<f:attribute name="selectedCA" value="#{row}" />
					</p:commandButton>
					<p:tooltip for="viewLink" value="View certificate authority" />
					<p:commandButton id="removeLink" icon="ui-icon-trash"
						actionListener="#{certificateAuthorityController.removeCandidate}"
						oncomplete="removeDialog.show()"
						update=":confirmForm:confirmButton,:messages">
						<f:attribute name="selectedCA" value="#{row}" />
					</p:commandButton>
					<p:tooltip for="removeLink" value="Remove certificate authority" />
				</h:panelGroup>
			</p:column>
		</p:dataTable>
	</h:form>
	<p:dialog header="Root Certificate Authority details"
		widgetVar="viewDialog" modal="true">
		<h:form id="viewDialogForm">
			<h:panelGrid columns="2">
				<h:outputText value="Name:" />
				<h:outputText
					value="#{certificateAuthorityController.selectedCA.name}" />

				<h:outputText value="Subject:" />
				<h:outputText
					value="#{certificateAuthorityController.selectedCA.subject}" />

				<h:outputText value="Key size:" />
				<h:outputText
					value="#{certificateAuthorityController.selectedCA.keySize}" />

				<h:outputText value="Not before:" />
				<h:outputText
					value="#{certificateAuthorityController.selectedCA.notBefore}">
					<f:convertDateTime pattern="dd/MM/yyyy HH:mm" timeZone="CET" />
				</h:outputText>

				<h:outputText value="Not after:" />
				<h:outputText
					value="#{certificateAuthorityController.selectedCA.notAfter}">
					<f:convertDateTime pattern="dd/MM/yyyy HH:mm" timeZone="CET" />
				</h:outputText>

				<h:outputText value="CRL validity (minutes):" />
				<h:outputText
					value="#{certificateAuthorityController.selectedCA.crlValidity}" />

				<h:outputText value="CRL overlap (minutes):" />
				<h:outputText
					value="#{certificateAuthorityController.selectedCA.crlOverlap}" />
			</h:panelGrid>
			<h:panelGrid columns="1">
				<p:commandButton value="Dismiss"
					actionListener="#{certificateAuthorityController.unselectCA}"
					oncomplete="viewDialog.hide();" icon="ui-icon-close" />
			</h:panelGrid>
		</h:form>
	</p:dialog>
	<p:dialog header="Add Certificate Authority" widgetVar="addDialog"
		modal="true">
		<h:form id="addDialogForm">
			<h:panelGrid columns="2" rowClasses="add-dialog-panelgrid-row">
				<p:fieldset legend="Root CA" styleClass="add-dialog-fieldset">
					<h:panelGrid columns="3">
						<h:outputText value="Name:" />
						<h:inputText id="name"
							value="#{certificateAuthorityController.name}" required="true" />
						<p:message for="name" />

						<h:outputText value="Subject:" />
						<h:inputText id="subject"
							value="#{certificateAuthorityController.subject}" required="true" />
						<p:message for="subject" />

						<h:outputText value="Key size:" />
						<p:selectOneButton id="keySize"
							value="#{certificateAuthorityController.keySize}" required="true">
							<f:selectItem itemLabel="1024" itemValue="1024" />
							<f:selectItem itemLabel="2048" itemValue="2048" />
							<f:selectItem itemLabel="4096" itemValue="4096" />
						</p:selectOneButton>
						<p:message for="keySize" />

						<h:outputText value="Validity (minutes): " />
						<h:panelGrid columns="1">
							<p:inputText id="validity"
								value="#{certificateAuthorityController.validity}"
								required="true" />
							<p:slider for="validity" />
						</h:panelGrid>
						<p:message for="validity" />

						<h:outputText value="Policy OID:" />
						<h:inputText id="policyOid"
							value="#{certificateAuthorityController.policyOid}"
							required="true" />
						<p:message for="policyOid" />

						<h:panelGroup>
							<h:outputText value="CPS:" id="cpsLabel" />
							<p:tooltip for="cpsLabel"
								value="Certificate Practice Statement URL" />
						</h:panelGroup>
						<h:inputText id="cps"
							value="#{certificateAuthorityController.cps}" required="true" />
						<p:message for="cps" />

						<h:outputText value="CRL validity (minutes):" />
						<h:panelGrid columns="1">
							<p:inputText id="crlValidity"
								value="#{certificateAuthorityController.crlValidity}"
								required="true" />
							<p:slider for="crlValidity" />
						</h:panelGrid>
						<p:message for="crlValidity" />

						<h:outputText value="CRL overlap (minutes):" />
						<h:panelGrid columns="1">
							<p:inputText id="crlOverlap"
								value="#{certificateAuthorityController.crlOverlap}"
								required="true" />
							<p:slider for="crlOverlap" />
						</h:panelGrid>
						<p:message for="crlOverlap" />
					</h:panelGrid>
				</p:fieldset>

				<p:fieldset legend="Intermediate CA"
					styleClass="add-dialog-fieldset">
					<h:panelGrid columns="3">
						<h:outputText value="Subject:" />
						<h:inputText id="interSubject"
							value="#{certificateAuthorityController.interSubject}"
							required="true" />
						<p:message for="interSubject" />

						<h:outputText value="Validity (minutes): " />
						<h:panelGrid columns="1">
							<p:inputText id="interValidity"
								value="#{certificateAuthorityController.interValidity}"
								required="true" />
							<p:slider for="interValidity" />
						</h:panelGrid>
						<p:message for="interValidity" />

						<h:outputText value="Policy OID:" />
						<h:inputText id="interPolicyOid"
							value="#{certificateAuthorityController.interPolicyOid}"
							required="true" />
						<p:message for="interPolicyOid" />

						<h:outputText value="Spawn interval (minutes): " />
						<h:panelGrid columns="1">
							<p:inputText id="interSpawnInterval"
								value="#{certificateAuthorityController.interSpawnInterval}"
								required="true" />
							<p:slider for="interSpawnInterval" />
						</h:panelGrid>
						<p:message for="interSpawnInterval" />

						<h:outputText value="Spawn count: " />
						<h:panelGrid columns="1">
							<p:inputText id="interSpawnCount"
								value="#{certificateAuthorityController.interSpawnCount}"
								required="true" />
							<p:slider for="interSpawnCount" />
						</h:panelGrid>
						<p:message for="interSpawnCount" />
					</h:panelGrid>
				</p:fieldset>
			</h:panelGrid>
			<h:panelGrid columns="2">
				<p:commandButton value="Add"
					actionListener="#{certificateAuthorityController.add}"
					oncomplete="handleAddCARequest(xhr, status, args)"
					update="addDialogForm,:caForm:table,:messages" icon="ui-icon-check" />
				<p:commandButton type="button" value="Dismiss"
					onclick="addDialog.hide();" icon="ui-icon-close" />
			</h:panelGrid>
		</h:form>
	</p:dialog>
	<p:confirmDialog header="Remove Certificate Authority"
		message="Are you sure to remove the CA?" severity="alert"
		widgetVar="removeDialog">
		<h:form id="confirmForm">
			<p:commandButton id="confirmButton" value="Yes"
				actionListener="#{certificateAuthorityController.removeCA}"
				oncomplete="removeDialog.hide()" update=":caForm:table,:messages"
				icon="ui-icon-check">
				<f:param name="cid"
					value="#{javax.enterprise.context.conversation.id}" />
			</p:commandButton>
			<p:commandButton value="No" onclick="removeDialog.hide()"
				icon="ui-icon-close" />
		</h:form>
	</p:confirmDialog>
</h:body>
</html>